package com.hwq.mynavigation;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

public class OneFragment extends Fragment {

    public OneFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view =  inflater.inflate(R.layout.fragment_one, container, false);
        //通过safe args完成参数接收
        Bundle bundle = getArguments();
        if(bundle != null){
            MainFragmentArgs args = MainFragmentArgs.fromBundle(getArguments());
            String userName = args.getUserName();
            int age = args.getAge();
            TextView tvSub = view.findViewById(R.id.tvSub);
            tvSub.setText(userName + age);
            tvSub.setOnClickListener((v)->{
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_oneFragment_to_mainFragment);
            });
        }
        return view;
    }
}